<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加分类 - 便签系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css" rel="stylesheet">
    <link href="/css/custom.css" rel="stylesheet">
    <!-- 颜色选择器 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@simonwep/pickr/dist/themes/classic.min.css">
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark">
        <div class="container">
            <a class="navbar-brand" href="/memo/list">
                <i class="bi bi-sticky me-2"></i>便签系统
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="/memo/list">
                            <i class="bi bi-collection me-1"></i>我的便签
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/memo/add">
                            <i class="bi bi-plus-circle me-1"></i>添加便签
                        </a>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle active" href="#" id="categoriesDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                            <i class="bi bi-tag me-1"></i>分类管理
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="categoriesDropdown">
                            <li><a class="dropdown-item" href="/category/list"><i class="bi bi-list-ul me-1"></i>查看分类</a></li>
                            <li><a class="dropdown-item active" href="/category/add"><i class="bi bi-plus-lg me-1"></i>添加分类</a></li>
                        </ul>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/memo/recycle-bin">
                            <i class="bi bi-trash me-1"></i>回收站
                        </a>
                    </li>
                </ul>
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link" href="/logout">
                            <i class="bi bi-box-arrow-right me-1"></i>退出登录
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container mt-4">
        <div class="row mb-4">
            <div class="col">
                <h2>
                    <i class="bi bi-tag-plus me-2"></i>添加分类
                </h2>
                <p class="text-muted">创建一个新的便签分类</p>
            </div>
        </div>
        
        <div class="card fade-in">
            <div class="card-body">
                <form action="/category/add" method="post" class="mt-2">
                    <div class="mb-4">
                        <label for="name" class="form-label">
                            <i class="bi bi-tag me-1"></i>分类名称
                        </label>
                        <input type="text" class="form-control" id="name" name="name" required>
                    </div>
                    <div class="mb-4">
                        <label for="color" class="form-label">
                            <i class="bi bi-palette me-1"></i>分类颜色
                        </label>
                        <div class="d-flex align-items-center">
                            <div id="color-picker" class="me-3"></div>
                            <input type="text" class="form-control" id="color" name="color" value="#4a6fa5" required readonly>
                        </div>
                        <div class="mt-3">
                            <div class="d-flex flex-wrap">
                                <div class="color-preset me-2 mb-2" data-color="#4a6fa5" style="background-color: #4a6fa5;"></div>
                                <div class="color-preset me-2 mb-2" data-color="#28a745" style="background-color: #28a745;"></div>
                                <div class="color-preset me-2 mb-2" data-color="#fd7e14" style="background-color: #fd7e14;"></div>
                                <div class="color-preset me-2 mb-2" data-color="#6f42c1" style="background-color: #6f42c1;"></div>
                                <div class="color-preset me-2 mb-2" data-color="#e83e8c" style="background-color: #e83e8c;"></div>
                                <div class="color-preset me-2 mb-2" data-color="#17a2b8" style="background-color: #17a2b8;"></div>
                                <div class="color-preset me-2 mb-2" data-color="#dc3545" style="background-color: #dc3545;"></div>
                                <div class="color-preset me-2 mb-2" data-color="#6c757d" style="background-color: #6c757d;"></div>
                            </div>
                        </div>
                    </div>
                    <div class="d-flex justify-content-between">
                        <a href="/category/list" class="btn btn-secondary">
                            <i class="bi bi-arrow-left me-1"></i>返回
                        </a>
                        <button type="submit" class="btn btn-primary">
                            <i class="bi bi-save me-1"></i>保存
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <!-- 颜色选择器 -->
    <script src="https://cdn.jsdelivr.net/npm/@simonwep/pickr/dist/pickr.min.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 初始化颜色选择器
            const pickr = Pickr.create({
                el: '#color-picker',
                theme: 'classic',
                default: '#4a6fa5',
                swatches: [
                    '#4a6fa5',
                    '#28a745',
                    '#fd7e14',
                    '#6f42c1',
                    '#e83e8c',
                    '#17a2b8',
                    '#dc3545',
                    '#6c757d'
                ],
                components: {
                    preview: true,
                    opacity: true,
                    hue: true,
                    interaction: {
                        hex: true,
                        rgba: true,
                        input: true,
                        save: true
                    }
                }
            });

            // 更新隐藏输入框的值
            pickr.on('save', (color, instance) => {
                document.getElementById('color').value = color.toHEXA().toString();
                instance.hide();
            });

            // 预设颜色点击事件
            document.querySelectorAll('.color-preset').forEach(preset => {
                preset.addEventListener('click', function() {
                    const color = this.getAttribute('data-color');
                    document.getElementById('color').value = color;
                    pickr.setColor(color);
                });
            });
        });
    </script>
    <style>
        .color-preset {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            cursor: pointer;
            transition: transform 0.2s;
        }
        .color-preset:hover {
            transform: scale(1.2);
        }
        #color-picker {
            width: 40px;
            height: 40px;
            border-radius: 50%;
        }
    </style>
</body>
</html> 